#ifndef GTCPSOCKET_H
#define GTCPSOCKET_H

#include<QTcpServer>
#include<QList>

#include"GUser.h"
#include"GLogin.h"

#include"GSupport.h"

/*!	\brief This object handles incoming connections.
 *	
 *	Once an incoming connection has been initiated this object
 *	creates new GUser objects to handle the connections. This
 *	object also sets up GChat to handle chat rooms management and
 *	sets up GLogin to handle account management.
 *	
 */
class GTcpServer : public QTcpServer {
	Q_OBJECT
public:
	/*!	\brief The constructor that initializes a few internal objects.
	 *	
	 *	
	 *	
	 *	@param parent The parent of this object.
	 *	
	*/
	GTcpServer(QObject* parent);
	
	/*!	\brief The destructor destroys all the internal objects.
	 *	
	 *	A messages is send to the login thread to initiate the
	 *	shutdown process.
	 *	
	*/
	~GTcpServer();
	
private:
	
	/*!	\brief This is the thread for account management and authenticating users.
	*/
	GLogin* logins;
	
protected:
	/*!	\brief Called when a client is connecting to the server.
	 *	
	 *	When the socket gets an incoming connection GTcpServer creates
	 *	a new GUser and makes the proper connections to the GChat instance,
	 *	GLogin instance and this instance.\n\n
	 *	Functions of Threads:\n
	 *	GChat - Handles chat room management and posting messages in the rooms.\n
	 *	GLogin - Handles authenticating users, GFriendsList status updates and
	 *	spamming messages to your GFriendsList.\n
	 *	GTcpServer - Handles incoming connections, all initial setup of the server,
	 *	single private messages and basic statistics (ie. number of people online).
	 *	
	 *	@see GUser
	 *	@see GLogin
	 *	@see GChat
	 *	@param sfd Stands for socket file descriptor. This is a number that points
	 *	to a socket that the GUser thread uses to setup a connection so it may
	 *	be able to receive data from the new client trying to connect to the
	 *	server.
	 *	
	*/
	void incomingConnection(int sfd);
	
	
	
signals:
	void closeDown();
	
public slots:
	void signalQuit();
	
};

#endif // GTCPSOCKET_H
